<script setup>
import { reactive, ref } from "vue";
import { useRouter, useRoute } from "vue-router";
import { request } from "../utils";
import { Toast } from "vant";
const form = reactive({
  username: "",
  password: "",
});
const router = useRouter();
const myform = ref(null);
const onSubmit = async function () {
  const { data } = await request.post("/user/reg", {
    username: form.username,
    password: form.password,
  });
  if (data.code === 200) {
    Toast.success("注册成功!");
    setTimeout(() => {
      Toast.clear("false");
      router.push("login");
    }, 500);
  }
  console.log(data);
};

const onClickLeft = () => history.back(console.log(6666));
</script>
<template>
  <div>
    <div>
      <van-nav-bar
        class="regnav"
        title="银豹收银"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
        style="background-color: #4496c6"
      />
    </div>
    <h3 style="text-align: center">免费注册银豹收银系统</h3>
    <div>
      <van-form @submit="onSubmit" ref="myform">
        <van-cell-group inset>
          <van-field
            v-model="form.username"
            name="用户名"
            placeholder="请输入手机号码"
            :rules="[{ required: true, message: '请填写用户名' }]"
            style="border-bottom: 1px solid #ccc"
          />
          <van-field
            v-model="form.password"
            type="password"
            name="密码"
            placeholder="请输入输入密码"
            :rules="[{ required: true, message: '请填写密码' }]"
            style="border-bottom: 1px solid #ccc"
          />
        </van-cell-group>
        <div style="margin: 16px">
          <van-button round block type="primary" native-type="submit">
            注册
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
<style lang="scss">
.regnav .van-nav-bar__text {
  color: white;
  .van-icon:before{
  color: white;
}
}

</style>